package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TmsController {
    @Autowired
    ServiceImpl service;
    @RequestMapping("/show")
    //19）实现统计各省份下单次数的省份热力图（5分）
    public Object show(){
        List<Map> show = service.show();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataobject = new JSONObject();
        JSONArray mapArray = new JSONArray();
        for (Map map : show) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("cc"));
            mapArray.add(jsonObject1);
        }
        dataobject.put("mapData",mapArray);
        jsonObject.put("data",dataobject);
        return jsonObject;
    }
    //18）实现统计各类货物下单次数占比的饼状图（5分）
    @RequestMapping("/show1")
    //19）实现统计各省份下单次数的省份热力图（5分）
    public Object show1(){
        List<Map> show = service.show1();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray objects = new JSONArray();
        for (Map map : show) {
            JSONObject dataobject = new JSONObject();
            dataobject.put("name",map.get("name"));
            dataobject.put("value",map.get("con"));
            objects.add(dataobject);
        }


        jsonObject.put("data",objects);
        return jsonObject;
    }
    //20）实现存储过程统计当日下单总金额的数字翻牌器（5分）
    @RequestMapping("/show2")
    public Object show2(){
        List<Map> list = service.show2();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("nn"));
        return jsonObject;
    }
    //13）统计各时段的下单人数（sql语句）（5分）
    @RequestMapping("/show3")
    public Object show3(){
        List<Map> list = service.show3();
        for (Map map : list) {
            System.out.println(map);
        }
        return list;
    }
    @RequestMapping("/show4")
    public Object show4(){
        List<Map> list = service.show4();
        for (Map map : list) {
            System.out.println(map);
        }
        return list;
    }
    @RequestMapping("/show5")
    public Object show5(){
        List<Map> list = service.show5();
        for (Map map : list) {
            System.out.println(map);
        }
        return list;
    }
}
